import 'package:equatable/equatable.dart';
import 'package:backend.purchases/domain/entities/app_store_api/app_store_api_purchased_subscription_expiration_reason.dart';

class AppStoreApiExpirationReasonDto extends Equatable {
  const AppStoreApiExpirationReasonDto._internal({
    required this.expirationReasonCode,
  });

  final int? expirationReasonCode;

  @override
  List<Object?> get props {
    return [
      expirationReasonCode,
    ];
  }

  factory AppStoreApiExpirationReasonDto.fromCode(int expirationReasonCode) {
    return AppStoreApiExpirationReasonDto._internal(
      expirationReasonCode: expirationReasonCode,
    );
  }

  AppStoreApiPurchasedSubscriptionExpirationReason toEntity() {
    if (expirationReasonCode == 1) {
      return AppStoreApiPurchasedSubscriptionExpirationReason.customerCancellation;
    }

    if (expirationReasonCode == 2) {
      return AppStoreApiPurchasedSubscriptionExpirationReason.billingError;
    }

    if (expirationReasonCode == 3) {
      return AppStoreApiPurchasedSubscriptionExpirationReason.priceIncrease;
    }

    if (expirationReasonCode == 4) {
      return AppStoreApiPurchasedSubscriptionExpirationReason.unavailablePurchase;
    }

    throw UnimplementedError();
  }
}
